package util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class JedisUtil {

    private static Jedis jedis;

    static {
        InputStream is =
                JedisUtil.class.getClassLoader().getResourceAsStream("jedispool.properties");
        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal")));
        config.setMaxTotal(Integer.parseInt(properties.getProperty("maxIdle")));
        JedisPool jedisPool =
                new JedisPool(config,properties.getProperty("host"),
                        Integer.parseInt(properties.getProperty("port")));
        jedis = jedisPool.getResource();

    }

    public static Jedis getJedis() {
        return jedis;
    }
}
